package com.bdqn.springweb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.springweb.mapper.UserMapper;
import com.bdqn.springweb.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("UserService")
public class UserServiceImpl implements Userservice {
    @Resource
    UserMapper UserMapper;

    /**
     * 根据id查询用户信息
     */
    @Override
    public User getUser(Long usrId) {
        return UserMapper.selectById(usrId);
    }

    /**
     * 查询所有的用户数据
     */
    @Override
    public List<User> findAllUsers() {
        return UserMapper.selectList(null);
    }

    /**
     * 新增用户
     */
    @Override
    public void addUser(User sysUser){
        UserMapper.insert(sysUser);
    }

    /**
     * 修改用户
     */
    @Override
    public void updateUser(User sysUser) {
        UserMapper.updateById(sysUser);
    }

    /**
     * 删除用户
     */
    @Override
    public void deleteUser(Long usrId) {
        UserMapper.deleteById(usrId);
    }

    /**
     * 登录
     */
    @Override
    public User login(String usrName, String usrPassword) {
        QueryWrapper<User> wrapper = new QueryWrapper<User>();
        wrapper.eq("usr_name", usrName);
        wrapper.eq("usr_password", usrPassword);
        return UserMapper.selectOne(wrapper);
    }
}
